

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>商品新增</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <#include "../../include/layui.ftl" />
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form layui-form-pane" action="/console/com.fs.common.pojo.IntegralProduct/modify" lay-filter="layer-from">
                <input type="hidden" name="id">
                <div class="layui-form-item">
                    <label class="layui-form-label">商品名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="productName" lay-verify="required" autocomplete="off" placeholder="请输入商品名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">商品兑换积分</label>
                    <div class="layui-input-block">
                        <input type="text" name="integral" lay-verify="required" autocomplete="off" placeholder="请输入商品兑换积分" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">商品类型</label>
                    <div class="layui-input-block">
                        <input type="text" name="type" lay-verify="" autocomplete="off" placeholder="请输入商品类型" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">商品简介</label>
                    <div class="layui-input-block">
                        <input type="text" name="productDescribe" lay-verify="" autocomplete="off" placeholder="请输入商品简介" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">商品状态</label>
                    <div class="layui-input-block">
                        <select name="state" lay-verify="required">
                            <option value=""></option>
                            <option value="0">有效</option>
                            <option value="1">无效</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">商品开始兑换时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="startTime" id="startTime" lay-verify="required" autocomplete="off" placeholder="请输入商品开始兑换时间" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">商品结束兑换时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="endTime" id="endTime" lay-verify="required" autocomplete="off" placeholder="请输入商品结束兑换时间" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">商品库存</label>
                    <div class="layui-input-block">
                        <input type="text" name="stock" lay-verify="" autocomplete="off" placeholder="请输入商品库存" class="layui-input">
                    </div>
                </div>
                <input type="hidden" name="productIcon" id="productIcon" lay-verify="" disabled autocomplete="off" placeholder="请输入图片" class="layui-input">
                <div class="layui-form-item" hidden>
                    <div class="layui-input-block">
                        <button id="permissionSubmit" class="layui-btn" lay-submit lay-filter="*">
                            保存
                        </button>
                    </div>
                </div>
            </form>

            <#--上传图片-->
            <div class="layui-upload">
                <button type="button" class="layui-btn" id="picture">编辑图片</button>
                <div class="layui-upload-list">
                    <img class="layui-upload-img" id="picture_preview" width="100" height="100" border="0">
                    <p id="reup"></p>
                </div>
            </div>

        </div>
    </div>
</div>


<script>
    layui.config({
        base: '${path}/plug-in/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','form','laydate','upload'], function(){
        var $ = layui.$
            ,laydate = layui.laydate
            ,upload = layui.upload
            ,form = layui.form;

        laydate.render({
            type:'datetime',
            elem: '#endTime'
        });
        laydate.render({
            type:'datetime',
            elem: '#startTime'
        });

        // 输入框复制值
        $("input[type=radio][name='shortCut'][value='"+parent._data.shortCut+"']").attr("checked",true);
        //form.render('checkbox')
        form.val("layer-from", $.extend(true,{},parent._data));

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#picture'
            ,url: '/console/layui/upload'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#picture_preview').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                $("#productIcon").val(res.data.url);
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var reup = $('#reup');
                reup.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                reup.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });

    });
</script>
</body>
</html>
